package com.ruoyi.controller;
import com.ruoyi.utils.AliOSSUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * @author Administrator
 * @date 2025/2/15
 * @description
 */

@RestController
@RequestMapping("/kangyue/upload")
public class UploadController {

    @PostMapping("/video")
    public String uploadVideo(@RequestParam("file") MultipartFile file) {
        System.out.println("00000000000000000000");

        if (file == null || file.isEmpty()) {
            System.out.println("文件错误");
        }
        try {
            System.out.println("开始上传---------------");
            String videoUrl = AliOSSUtils.uploadVideoToOSS(file);
            System.out.println("上传完成-----------------");
            return videoUrl;
        } catch (Exception e) {
            e.printStackTrace();
            return "上传失败: " + e.getMessage();
        }
    }


    @PostMapping("/image")
    public String uploadImage(@RequestParam("file") MultipartFile file) {
        try {
            System.out.println("开始上传图片-----------");
            // 调用 OSSUploader 工具类上传文件
            String imageUrl = AliOSSUtils.upload(file);
            System.out.println("上传图片完成----------");
            return imageUrl;
        } catch (Exception e) {
            e.printStackTrace();
            return "上传失败: " + e.getMessage();
        }
    }
}
